all files / Services/ string-helper.service.ts

100% Statements 20/20
100% Branches 4/4
100% Functions 5/5
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                     30×              
import { Injectable } from '@angular/core';
 
import { MathHelper } from './math-helper.service';
 
@Injectable()
export class StringHelper {
 
    constructor(
        private math: MathHelper) {
 
    }
 
    isNullOrEmpty(data: string): boolean {
        return data == null || data == '';
    }
 
    randomString(): string {
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
        for (var i = 0; i < 10; i++)
            text += possible.charAt(this.math.floor(this.math.random() * possible.length));
 
        return text;
    }
 
    randomIfNullOrEmpty(evalString: string): string {
 
        if (this.isNullOrEmpty(evalString)) {
            return this.randomString();
        } else {
            return evalString;
        }
    }
}